package org.jsbd.boss.task;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.bto.HttpResult;
import org.jsbd.boss.domian.channel.SmsSyncVo;
import org.jsbd.boss.service.IChannelTaskService;
import org.jsbd.boss.util.SpringContextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * @desc
 * @Date 2018/10/18 16:06
 * @Author xupengcheng [xupengcheng@zhexinit.com]
 */
public class PreserveLoginTask implements Runnable, Serializable {

    public static final Logger logger = LoggerFactory.getLogger(PreserveLoginTask.class);
    private static final long serialVersionUID = 1L;
    private HttpResult httpResult;

    public PreserveLoginTask(HttpResult httpResult) {
        this.httpResult = httpResult;
    }

    @Override
    public void run() {
        String orderId = httpResult.getId();
        try {
            String resultCode = httpResult.getResultCode();
            String sms = httpResult.getSms();
            // 是否走新流程 的判断
            int index = orderId.indexOf("_");
            String imsi = orderId.substring(0, index);
            if (StringUtils.isBlank(imsi) || "null".equals(imsi)) {
                return;
            } else {
                SmsSyncVo smsVo = new SmsSyncVo();
                smsVo.setOrderId(orderId);
                smsVo.setResultCode(resultCode);
                smsVo.setSms(sms);
                SpringContextUtils.getBean(IChannelTaskService.class).syncSmsTask(smsVo);
            }
        } catch (Exception e) {
            logger.error("处理结果出错 {} {}", orderId, e);
        }
    }
}
